/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package threads;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import componentes.Configuracao;
import excessoes.LloginNuloException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import principal.Main;

/**
 *
 * @author Wagner Tavares
 */
public class InsercaoBloqueado extends Consulta implements Runnable{
    private String ip;
    private Connection con;
    public InsercaoBloqueado(Configuracao config, String ip) throws LloginNuloException{
        super(config);
        this.ip=ip;
    }
    public void run() {
        try {
            Date date = new Date();
            String data = (date.getYear()+1900) + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
            query = "update log_logins set t_logout = '"+data+"' where ip = '"+ip+"' and t_logout = '0000-00-00 00:00:00'";

            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://ads.fortalnet.com.br/cadastroparceiro?user=root&password=qwe!@#$");
            PreparedStatement st = (PreparedStatement) con.prepareStatement(query);
            st.execute();
            st.close();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }  catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Erro ao se conectar ao banco de dados", ex);
        }
        
    }
    public void start(){
        Thread insercaoBloqueadoThread = new Thread(this,"insercaoBloqueadoThread");
        insercaoBloqueadoThread.setPriority(2);
        insercaoBloqueadoThread.start();
    }
}
